package com.byxy.service.impl;

import java.util.List;

import javax.annotation.Resource;
import javax.transaction.Transactional;

import org.springframework.stereotype.Service;

import com.byxy.dao.LineDao;
import com.byxy.dao.OrderDao;
import com.byxy.entity.Line;
import com.byxy.entity.Order;
import com.byxy.service.LineService;

@Service
@Transactional
public class LineServiceImpl implements LineService {
	@Resource
	private LineDao lineDao;
	@Resource
	private OrderDao orderDao;

	@Override
	public List<Line> listAll() {
		return lineDao.find();
	}

	@Override
	public void delete(int id) {
		Line s = lineDao.get(id);
		for (Order order : s.getOrders()) {
			order.setLine(null);
		}
		lineDao.delete(s);

	}

	@Override
	public void save(Line line) {
		lineDao.add(line);
	}

	@Override
	public Line getById(int id) {

		return lineDao.get(id);
	}

	@Override
	public void update(Line line) {
		lineDao.update(line);

	}

	@Override
	public List<Line> listPage(int page, int rows) {
		int pos = (page - 1) * rows;
		return lineDao.find(pos, rows);
	}

	@Override
	public long count() {
		return lineDao.count();
	}

}
